﻿using System.Configuration;
using System.Text;
using Selenium;
using NUnit.Framework;

namespace Medianamik.Tests.Selenium
{
    public class BaseSeleniumFixture
    {
        protected SeleniumManager mng;
        protected StringBuilder verificationErrors;

        public string BaseTestUrl
        {
            get
            {
                string value = ConfigurationManager.AppSettings["BaseTestUrl"];
                if (value.EndsWith("/"))
                    return value;
                return value + "/";
            }
        }

        protected ISelenium selenium
        {
            get
            {
                return mng.selenium;
            }
        }

        [SetUp]
        public void SetupTest()
        {
            mng = new SeleniumManager();
            mng.Start();
        }

        [TearDown]
        public void TeardownTest()
        {
            try
            {
                mng.Stop();
            }
            catch
            {
                // Ignore errors if unable to close the browser
            }
            Assert.AreEqual("", mng.verificationErrors.ToString());
        }

        [TestFixtureTearDown]
        public void Cleanup()
        {
            mng.RestoreDatabaseState();
        }

    }
}